package com.bcinfo.iccard.msg;

import java.io.IOException;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.log4j.Logger;

import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.MessageFactory;
import com.solab.iso8583.parse.ConfigParser;
/**
 * ISO8583消息工厂类单例
 * @author wangguangchun
 *
 */
public class ISOMessageFactory {
	private static Logger _logger=Logger.getLogger(ISOMessageFactory.class);
	private static MessageFactory<IsoMessage> instance;
	private ISOMessageFactory(){
	}
	public static MessageFactory<IsoMessage> getInstance(){
		if(instance==null){
			try {
				instance=ConfigParser.createFromClasspathConfig("j8583.xml");
			} catch (IOException e) {
				_logger.error(ExceptionUtils.getStackTrace(e));
			}
		}
		return instance;
	}
	public static void print(IsoMessage m){
		System.out.printf("TYPE: %04x\n", m.getType());
		for (int i = 2; i < 128; i++) {
			if (m.hasField(i)) {
				System.out.printf("F %3d(%s): %s -> '%s'\n", i, m.getField(i)
						.getType(), m.getObjectValue(i), m.getField(i)
						.toString());
			}
		}
	}
}
